from ..extensions import db
from datetime import datetime

class Staff(db.Model):
    __tablename__ = 'staff'
    
    id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"), primary_key=True, autoincrement=True, comment='服务人员ID')
    name = db.Column(db.String(100), nullable=False, comment='姓名')
    work_years = db.Column(db.Integer, nullable=False, default=0, comment='工龄（年）')
    gender = db.Column(db.String(1), nullable=True, comment='性别，M=男，F=女')
    job_type = db.Column(db.String(100), nullable=True, comment='工种')
    is_on_duty = db.Column(db.Integer, nullable=False, default=True, comment='是否在岗，0=不在岗，1=在岗')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='记录创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'work_years': self.work_years,
            'gender': self.gender,
            'job_type': self.job_type,
            'is_on_duty': bool(self.is_on_duty),
            'created_at': str(self.created_at)
        }